import CryptoJS from 'crypto-js';

const CRYPTOJSKEY = '8opar2lzva1be6cb';

//加密
function getEncryption(plaintText) {
  var plaintText = plaintText;
  var options = {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  };
  var key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
  var encryptedData = CryptoJS.AES.encrypt(plaintText, key, options);
  var encryptedBase64Str = encryptedData.toString();
  return encryptedBase64Str;
}
//解密
function getDecryption(encryptedBase64Str) {
  var vals = encryptedBase64Str;
  var options = {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  };
  var key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
  var decryptedData = CryptoJS.AES.decrypt(vals, key, options);
  var decryptedStr = CryptoJS.enc.Utf8.stringify(decryptedData);
  return decryptedStr;
}

export { getEncryption, getDecryption };
